import { Injectable } from '@nestjs/common';
import { In, Repository } from 'typeorm';
import RoleResourceLink from '../entity/role_resource.link';
@Injectable()
export default class lRoleResourceRepository extends Repository<RoleResourceLink> {
  async getResourceIdsByRoleId(roleId: string) {
    return await this.find({
      where: { roleId },
    }).then((l) => l.map((l) => l.resourceId));
  }

  async getResourceIdsByRoleIds(roleIds: string[]) {
    const resourceIds = await this.find({
      where: { roleId: In(roleIds) },
    }).then((l) => l.map((l) => l.resourceId));
    return [...new Set([...resourceIds])];
  }
}
